﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;
using System.Collections;

namespace com.intellitack.layar.library
{
    //POIActionConverter required to Serailize the POIAction due to the replacement mechanism of
    //the uri attribute.  The OOB JavaScriptSerializer inserts as special character.
    public class LayerCustomConverter : JavaScriptConverter
    {
        public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            throw new NotImplementedException();
        }

        public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer)
        {
            POIAction poiAction = obj as POIAction;

            if (poiAction != null)
            {
                //Create the return IDictionary Object
                Dictionary<string, object> result = new Dictionary<string, object>();
                result.Add("uri", poiAction.uri);
                result.Add("label", poiAction.label);
                //Add each attributes to the dictionary

                return result;
            }
            else
            {
                throw new ApplicationException(string.Format("Unable to Serialize type {0} in Serialize method for POIActionConverter", obj.GetType().ToString()));
            }

        }

        public override IEnumerable<Type> SupportedTypes
        {
            get
            {
                //Define the list of Supported Types
                List<Type> supportedTypes = new List<Type>();
                supportedTypes.Add(typeof(POIAction));
                return supportedTypes;
            }
        }
    }
}
